package com.xiaobao.coalproperty.module.user.view;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.google.gson.Gson;
import com.xiaobao.coalproperty.R;
import com.xiaobao.coalproperty.module.home.model.entity.BlankEntity;
import com.xiaobao.coalproperty.other.base.BaseActivity;
import com.xiaobao.coalproperty.other.constant.UrlConstant;
import com.xiaobao.coalproperty.other.util.HttpHelperUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import okhttp3.Call;

public class RePasswordActivity extends BaseActivity {


    @BindView(R.id.old)
    EditText edtOld;
    @BindView(R.id.new_pwd)
    EditText edtNewPwd;
    @BindView(R.id.pwd_again)
    EditText edtPwdAgain;

    @Override
    protected int getContentView() {
        return R.layout.activity_repassword;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setLeftClickFinish();
        setTitle("修改密码");
    }

    public void onRePasswordClick(View view) {
        OkHttpUtils.post().url(UrlConstant.URL_UPDATE_PWD)
                .params(HttpHelperUtils.getInstance().updateTransactionPwdParams(edtOld.getText().toString(), edtNewPwd.getText().toString(), edtPwdAgain.getText().toString()))
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                showToast(e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                try {
                    BlankEntity entity = new Gson().fromJson(response, BlankEntity.class);
                    showToast(entity.getMsg());
                    if (entity.getCode() == 0) {
                        finish();
                    }
                } catch (Exception e) {
                }
            }
        });
    }
}
